package guoanmaker.operator.business.controller;

import guoanmaker.operator.business.model.OperatorActivityType;
import guoanmaker.operator.business.service.OperatorActivityTypeServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 *  
 *
 * @author huZhaoyu 
 * @ClassName: OperatorActivityTypeController
 * @Description: OperatorActivityTypeController 
 * @date 2017/6/29 上午10:11 
 */
@RestController
@RequestMapping(ApiController.OPERATOR_ACTIVITY_TYPE)
public class OperatorActivityTypeController {
    private final OperatorActivityTypeServiceInterface operatorActivityTypeServiceInterface;

    public OperatorActivityTypeController(OperatorActivityTypeServiceInterface operatorActivityTypeServiceInterface) {
        this.operatorActivityTypeServiceInterface = operatorActivityTypeServiceInterface;
    }

    /** 
    * @Title: saveActivityType
    * @Description: 新增/修改活动类型 
    * @param: OperatorActivityType   
    * @return AjaxJson    
    * @throws 
    */
    @ApiOperation(value = "保存活动类型", notes = "新增/修改活动类型")
    @PostMapping(value = "saveActivityType")
    public AjaxJson saveActivityType(@RequestBody OperatorActivityType operatorActivityType) {
    	AjaxJson ajaxJson=new AjaxJson();
    	OperatorActivityType ActivityType=operatorActivityTypeServiceInterface.saveActivityType(operatorActivityType);
        if(ActivityType ==null){
        return ajaxJson.setSuccess(false).setStatus(101).setData(null).setMsg("分类名称重复");
        }
        return ajaxJson.setSuccess(true).setStatus(200).setData(ActivityType);
    }

    /** 
     * @Title: deleteActivityTypeById
     * @Description: 根据Id删除活动类型
     * @param: String id  
     * @return AjaxJson 
     * @throws 
     */
    @ApiOperation(value = "删除活动类型", notes = "根据Id删除活动类型")
    @PostMapping(value = "deleteActivityTypeById/{id}")
    public AjaxJson deleteActivityTypeById(@PathVariable(value = "id") String id) {
    	AjaxJson ajaxJson=new AjaxJson();
        operatorActivityTypeServiceInterface.deleteActivityTypeById(id);
        return ajaxJson.setSuccess(true).setStatus(200).setData("数据删除成功!");
    }

    /**
     * @return OperatorActivityType    
     * @Title: getActivityTypeById 
     * @Description: 根据Id查询活动类型
     * @param: String id   
     * @throws 
     */
    @ApiOperation(value = "根据Id查询活动类型", notes = "根据Id查询活动类型")
    @GetMapping(value = "getActivityTypeById")
    public AjaxJson getActivityTypeById(@RequestParam(value = "id") String id) {
    	AjaxJson ajaxJson=new AjaxJson();
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorActivityTypeServiceInterface.getActivityTypeById(id));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllActivityType
     * @Description: 查找所有活动类型 
     * @throws 
     */
    @ApiOperation(value = "查找所有活动类型", notes = "查找所有活动类型")
    @GetMapping(value = "getAllActivityType")
    public AjaxJson getAllActivityType() {
    	AjaxJson ajaxJson=new AjaxJson();
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorActivityTypeServiceInterface.getAllActivityType());
    }

    /**
     * @return AjaxJson   
     * @Title: getAllActivityTypeByPage 
     * @Description: 查询所有活动类型并分页
     * @param: Integer page 页码
     * @param: Integer size 条数
     * @throws 
     */
    @ApiOperation(value = "分页查询活动类型", notes = "分页查询活动类型")
    @PostMapping(value = "getAllActivityTypeByPage")
    public AjaxJson getAllActivityTypeByPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "10") Integer size) {
    	AjaxJson ajaxJson=new AjaxJson();
    	return ajaxJson.setSuccess(true).setStatus(200).setData(operatorActivityTypeServiceInterface.getAllActivityTypeByPage(page, size));
    }

    /**
     * @return AjaxJson   
     * @Title: getActivityTypeByPageOrderByWeight 
     * @Description: 按权重排序查询活动类型并分页 
     * @param: Integer page 页码
     * @param: Integer size 条数
     * @throws 
     */
    @ApiOperation(value = "按权重排序查询活动类型并分页", notes = "按权重排序查询活动类型并分页")
    @GetMapping(value = "getActivityTypeOrderByWeight")
    public AjaxJson getActivityTypeByPageOrderByWeight(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                             @RequestParam(value = "size", defaultValue = "10") Integer size) {
    	AjaxJson ajaxJson=new AjaxJson();
    	return ajaxJson.setSuccess(true).setStatus(200).setData(operatorActivityTypeServiceInterface.getActivityTypeByPageOrderByWeight(page, size));
    }

}
